package cn.wolfcode.crud.web.controller;


import cn.wolfcode.crud.domain.CustomerTransFer;
import cn.wolfcode.crud.service.ICustomerTransFerService;
import cn.wolfcode.crud.qo.QuerObjcet;
import cn.wolfcode.crud.qo.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransFer")
public class CustomerTransFerController {

    @Autowired
    private ICustomerTransFerService customerTransFerService;


    @RequiresPermissions(value = {"customerTransFer:list","客户移交历史明细页面"},logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QuerObjcet qo){
        PageInfo<CustomerTransFer> pageInfo = customerTransFerService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "customerTransFer/list";
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = {"customerTransFer:delete","客户移交历史明细删除"},logical = Logical.OR)
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            customerTransFerService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"customerTransFer:saveOrUpdate","客户移交历史明细新增/编辑"},logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTransFer customerTransFer){
        if (customerTransFer.getId() != null) {
            customerTransFerService.update(customerTransFer);
        }else {
            customerTransFerService.save(customerTransFer);
        }
        return new JsonResult();
    }
}
